<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            text-align: center;
        }

        input {
            width: 300px;
            height: 30px;
            color: #999;
            font-size: 18px;
        }
    </style>
</head>

<body>
    <form action="">
        <input type="text" value="手机">
    </form>
    <script>
        //获取body元素
        // var bodyElem = document.body;
        // console.log(bodyElem);
        // console.dir(bodyElem);
        //获取html元素
        // var htmlElem = document.documentElement;
        // console.log(htmlElem);



        var search = document.querySelector('input');
        // search.onfocus = function () {
        //     if (this.value == '手机') {
        //         this.value = '';
        //     }
        //     this.style.color = "#333";
        // }
        // search.onblur = function () {
        //     if (this.value == '') {
        //         this.value = '手机';
        //     }
        //     this.style.color = "#999";
        // }
        search.onfocus = change("#333");
        search.onblur = change("#999");
        function change(color) {
            return function () {
                if (this.value == '手机') {
                    this.value = '';
                } else if (this.value == '') {
                    this.value = '手机'
                }
                this.style.color = color;
            }
        }
    </script>
</body>

</html>